import {AMapWX} from './amap-wx.130';
export class AMap
{
    private Amap:any;
    private ready:boolean=false;
    constructor(config:any,callback?:Function){
        if(!config.amap_mini_key){
            console.log('amap_mini_key is required');
            return;
        }
        this.Amap = new AMapWX({
            key:config.amap_mini_key
        });
        this.ready=true;
        typeof callback==='function'&&callback();
    }
    isReady(){
        return this.ready;
    }
    createMap(id:string){
        return new Promise((resolve,reject)=>{
            resolve(true);
        });
    }
    createMarker(map:any,lnglat:any){
        return new Promise((resolve,reject)=>{
            return reject('map is not ready');
        });
    }
    getCurrentPosition(option?:any){
        const options:any={
            ...option
        };
        return new Promise((resolve,reject)=>{
            this.Amap.getRegeo({
                ...options,
                success:(res:any)=>{
                    resolve(res[0]);
                },
                fail:(res:any)=>{
                    console.log(res);
                    reject(res);
                }
            })
        });
    }
    getPosition(address:any){
        return new Promise((resolve,reject)=>{
            return reject('map is not ready');
        });
    }
    getAddress(lnglat:any){
        return new Promise((resolve,reject)=>{
            this.Amap.getRegeo({
                location:lnglat.join(','),
                success:(res:any)=>{
                    resolve(res[0]);
                },
                fail:(res:any)=>{
                    console.log(res);
                    reject(res);
                }
            })
        });
    }
    destroy(){}
}